package com.codeforces;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;


public class _303C {

	static InputReader reader = new InputReader(System.in);
	static int n;
	static int[] num;
	static long sum, tsum;
	
	public static void main(String[] args) {
		
		reader.nextLine();
        n = reader.nextInt();
        
        reader.nextLine();
		num = new int[n];
		for (int i=0;i<n;++i) {
			num[i] = reader.nextInt();
		}
		Arrays.sort(num);
		int tmp = 1;
		int next = n - tmp + 1;;
		int i = n-1;
		sum = tsum = 0;
		do {
			tsum += (long)num[i];
			if (i + 1 == next) {
				sum += tsum;
				tmp *= 4;
				next = n - tmp + 1;
			}
			--i;
		} while (next > 0);

		System.out.println(sum);
	}

}
class InputReader {
    BufferedReader reader;
    StringTokenizer token;

    InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
    }

    String next() {
        return token.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(this.next());
    }

    double nextDouble() {
        return Double.parseDouble(this.next());
    }

    long nextLong() {
        return Long.parseLong(this.next());
    }

    String nextLine() {
        String line = "";
        try {
            line = reader.readLine();
            token = new StringTokenizer(line, " ");

        } catch(IOException e) {

        }
        return line;
    }
}
